<template>
  	<div class="login_page">	
		<div style="margin-left:40px;font-size:26px;padding-top:15px;">
			<p>企业官网产品在线后台管理系统</p>
		</div>
		<div style="width:400px;">
			<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
				<br>
				<el-form-item label="用户名" prop="name">
					<el-input v-model="ruleForm.name"></el-input>
				</el-form-item>
				
				<el-form-item label="密码" prop="pass">
					<el-input type="password" v-model="ruleForm.pass"></el-input>
				</el-form-item>
				<br>
				<el-form-item>
					<el-button type="primary" @click="submitForm('ruleForm')" style="width:300px;">登陆</el-button>
				</el-form-item>
			</el-form>
		</div>
  	</div>
</template>

<script>
import { LoginSubmit } from '@/server/index.js'
import { saveLogin } from '@/utils/localStoreUtils.js'

	export default {
	    data(){
			return {
				ruleForm: {
					name: '',
					pass: '',
				},
				rules: {
					name: [
						{ required: true, message: '请输入用户名', trigger: 'blur' }
					],
					pass: [
						{ required: true, message: '请输入密码', trigger: 'blur' }
					]
				},
				
			}
		},
		mounted(){
			
		},
		computed: {
			
		},
		methods: {
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
				if (valid) {
					let dto = {username:this.ruleForm.name, password:this.ruleForm.pass}
					LoginSubmit(dto).then((response)=>{
						if(response.data.msg == 'ok'){
							saveLogin(response.data.token);
							this.$router.push("/home");
							this.$message.success("登录成功");
						}else{
							this.$message.error("用户名或密码错误");
						}
					});
				} else {
					this.$message.error("请输入用户名密码");
					return false;
				}
				});
			}
		},
		watch: {
			
		}
	}
</script>

<style scoped>
	.login_page{
		height: 350px;
		width: 450px;
		margin: 100px 33%;
		background-color:#909399;
	}
	
</style>
